package com.jianzong.lingxuan.admin.controller;

import cn.hutool.core.util.ObjectUtil;
import com.jianzong.lingxuan.admin.service.AdminService;
import com.jianzong.lingxuan.api.service.ApiService;
import com.jianzong.lingxuan.base.Result;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


/**
 * @auth Leiwenlong
 * @since 2021/7/19
 */
@RestController
@RequestMapping("/admin")
public class AdminController {

    public final AdminService adminService;

    public AdminController(AdminService adminService){
        this.adminService = adminService;
    }

    @GetMapping("/base")
    @CrossOrigin
    public Result action(HttpServletRequest request){
        //1.获取所有请求参数
        Map<String, String[]> parameterMap = request.getParameterMap();

        String token = "";
        if(ObjectUtil.isNotNull(request.getHeader("token"))){
            token = request.getHeader("token");
        }

        if(0 == parameterMap.size()){
            return Result.error();
        }else{
            //调用
            return adminService.action(parameterMap,token);
        }

    }
}
